/// Comparison functions for integers.
/// These functions are generic over any type `T` that implements `Eq` and `Ord`.

/// Checks if two integers are equal.
///
/// # Arguments
///
/// * `location1` - A reference to the first integer.
/// * `location2` - A reference to the second integer.
///
/// # Returns
///
/// Returns `true` if the integers are equal, `false` otherwise.
pub fn int_equal<T: Eq>(location1: &T, location2: &T) -> bool {
    location1 == location2
}

/// Compares two integers.
///
/// # Arguments
///
/// * `location1` - A reference to the first integer.
/// * `location2` - A reference to the second integer.
///
/// # Returns
///
/// Returns:
/// * `-1` if `location1` is less than `location2`.
/// * `1` if `location1` is greater than `location2`.
/// * `0` if `location1` is equal to `location2`.
pub fn int_compare<T: Ord>(location1: &T, location2: &T) -> i32 {
    if location1 < location2 {
        -1
    } else if location1 > location2 {
        1
    } else {
        0
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_int_equal() {
        let a: i32 = 5;
        let b: i32 = 5;
        let c: i32 = 10;

        assert!(int_equal(&a, &b));
        assert!(!int_equal(&a, &c));
    }

    #[test]
    fn test_int_compare() {
        let a: i32 = 5;
        let b: i32 = 10;
        let c: i32 = 5;

        assert_eq!(int_compare(&a, &b), -1);
        assert_eq!(int_compare(&b, &a), 1);
        assert_eq!(int_compare(&a, &c), 0);
    }
}
